from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from meiduo_mall import settings
from itsdangerous import BadData,BadTimeSignature,SignatureExpired
#加密
def generic_openid(openid):
    s=Serializer(settings.SECRET_KEY, expires_in=3600)
    access_token=s.dumps({'openid':openid})
    #将bytes类型的数据转换为str
    return access_token.decode()


#解密
def check_access_token(access_token):
    print(access_token)
    s=Serializer(settings.SECRET_KEY, expires_in=3600)
    try:
       print(s)
       result= s.loads(access_token)
       print(result)
    except Exception:
        #返回None
        return None
    else:
        return result.get('openid')
